<?php defined('SYSPATH') or die('No direct access allowed.');
/**
 * PHOTOVOICE helper class.
 *
 * @category   Helpers
 * @author     Krutil Jonas
 * @copyright  (c) 2010
 */
class Helpers_Photovoice {

  /**
   * Create Avatar image or default
   *
   *     echo Photovoice::avatar('username');
   *
   * @param   string  username  logIn user
   * @return  string
   */
  public static function avatar($username) {

    $path = 'files/users/'.$username.'/'.$username.'.gif';

    if (file_exists($path)) {
      return '<img src="'.url::base().$path.'" class="avatar" alt="'.$username.'\'s avatar" />';
    } else {
      return '<img src="/files/avatar.gif" class="avatar" alt="default" />';
    }

  }

  public static function datum($time, $option = NULL) {

    settype($time, "integer");

    $aj = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    $cz = array("Leden", "Únor", "Březen", "Duben", "Květen", "Červen", "Červenec", "Srpen", "Září", "Říjen", "Listopad", "Prosinec");
    $today = strtotime(date('M j, Y'));

    $reldays = ($time - $today) / 86400;

    if ($reldays >= 0 && $reldays < 1) {
      return 'Dnes' . Date(" H:i", $time);
    } else if ($reldays >= -1 && $reldays < 0) {
      return 'Včera' . Date(" H:i", $time);
    } else {
      if (Date("Y", $time) === Date("Y", time())) {
        if ($option == 'full') {
          return str_replace($aj, $cz, Date("j. F H:i", $time));
        } else {
          return str_replace($aj, $cz, Date("j. F", $time));
        }
      } else {
        if ($option == 'full') {
          return str_replace($aj, $cz, Date("j. F Y H:i", $time));
        } else {
          return str_replace($aj, $cz, Date("j. F Y", $time));
        }
      }
    }
  }

} // End photovoice

